package com.machinecontroller.utils;

import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.SoftReference;

/**
 * @author Administrator
 */
public class BitmapUtil {

    /**
     * 保存Bitmap到相册
     *
     * @param bmp
     * @param path
     * @param fileName
     * @return
     */
    public static boolean saveBitmap2JPEG(Bitmap bmp, String path, String fileName) {
        boolean flag = false;
        File file = new File(path);
        if (!file.exists()) {
            file.mkdirs();
        }
        File fileImg = new File(path, fileName);
        if (fileImg.exists()) {
            fileImg.delete();
        }
        try {
            FileOutputStream out = new FileOutputStream(fileImg);
            flag = bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
            out.flush();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return flag;
    }


}
